Skip to content

[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks#33758

Open
william051200 wants to merge 20 commits into
Azure:devfrom
william051200:lifecycle-hooks
Open

[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks#33758
william051200 wants to merge 20 commits into
Azure:devfrom
william051200:lifecycle-hooks

Conversation

@william051200

@william051200 william051200 commented Jul 21, 2026

Copy link
Copy Markdown
Member

Related command

az vmss lifecycle-hook add/list/remove/show/update
az vmss lifecycle-hook-event approve/list/reject/show/update

Description

Resolve #33652

aaz Azure/aaz#1046

Testing Guide

Refer to azure-cli\src\azure-cli\azure\cli\command_modules\vm\tests\latest\test_vm_commands.py:

  1. test_vmss_lifecycle_hook
  2. test_vmss_lifecycle_hook_event

az vmss lifecycle-hook-event approve/reject/update are not included in the test cases as they required live platform-generated event. Service team will be helping with the test locally.

History Notes

[Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks


This checklist is used to make sure that common guidelines for a pull request are followed.

🤖 PR Validation — ❌ Action needed

Breaking Changes Tests
⚠️ None ❌ 129/130
⚠️AzureCLI-BreakingChangeTest
⚠️vm
rule cmd_name rule_message suggest_message
⚠️ 1011 - SubgroupAdd vmss lifecycle-hook sub group vmss lifecycle-hook added
⚠️ 1011 - SubgroupAdd vmss lifecycle-hook-event sub group vmss lifecycle-hook-event added
❌AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.14
🔄acs
🔄latest
🔄3.12
🔄3.14
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.14
️✔️ams
️✔️latest
️✔️3.12
️✔️3.14
🔄apim
🔄latest
🔄3.12
🔄3.14
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.14
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.14
🔄aro
🔄latest
🔄3.12
🔄3.14
🔄backup
🔄latest
🔄3.12
🔄3.14
️✔️batch
️✔️latest
️✔️3.12
️✔️3.14
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.14
🔄billing
🔄latest
🔄3.12
️✔️3.14
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.14
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.14
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.14
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.14
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.14
️✔️config
️✔️latest
️✔️3.12
️✔️3.14
️✔️configure
️✔️latest
️✔️3.12
️✔️3.14
🔄consumption
🔄latest
️✔️3.12
🔄3.14
️✔️container
️✔️latest
️✔️3.12
️✔️3.14
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.14
️✔️core
️✔️latest
️✔️3.12
️✔️3.14
🔄cosmosdb
🔄latest
🔄3.12
🔄3.14
🔄databoxedge
🔄latest
🔄3.12
️✔️3.14
🔄dls
🔄latest
🔄3.12
️✔️3.14
️✔️dms
️✔️latest
️✔️3.12
️✔️3.14
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.14
🔄eventhubs
🔄latest
🔄3.12
🔄3.14
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.14
️✔️find
️✔️latest
️✔️3.12
️✔️3.14
🔄hdinsight
🔄latest
🔄3.12
🔄3.14
🔄identity
🔄latest
🔄3.12
🔄3.14
️✔️iot
️✔️latest
️✔️3.12
️✔️3.14
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.14
️✔️lab
️✔️latest
️✔️3.12
️✔️3.14
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.14
🔄maps
🔄latest
️✔️3.12
🔄3.14
🔄marketplaceordering
🔄latest
🔄3.12
️✔️3.14
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.14
🔄mysql
🔄latest
🔄3.12
🔄3.14
🔄netappfiles
🔄latest
🔄3.12
🔄3.14
🔄network
🔄latest
️✔️3.12
🔄3.14
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.14
🔄postgresql
🔄latest
🔄3.12
🔄3.14
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.14
️✔️profile
️✔️latest
️✔️3.12
️✔️3.14
🔄rdbms
🔄latest
🔄3.12
🔄3.14
️✔️redis
️✔️latest
️✔️3.12
️✔️3.14
🔄relay
🔄latest
🔄3.12
🔄3.14
️✔️resource
️✔️latest
️✔️3.12
️✔️3.14
️✔️role
️✔️latest
️✔️3.12
️✔️3.14
️✔️search
️✔️latest
️✔️3.12
️✔️3.14
️✔️security
️✔️latest
️✔️3.12
️✔️3.14
🔄servicebus
🔄latest
🔄3.12
🔄3.14
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.14
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.14
🔄signalr
🔄latest
🔄3.12
🔄3.14
️✔️sql
️✔️latest
️✔️3.12
️✔️3.14
🔄sqlvm
🔄latest
🔄3.12
🔄3.14
🔄storage
🔄latest
🔄3.12
🔄3.14
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.14
🔄telemetry
🔄latest
️✔️3.12
🔄3.14
️✔️util
️✔️latest
️✔️3.12
️✔️3.14
❌vm
❌latest
🔄3.12
❌3.14
Type Test Case Error Message Line
Failed test_vmss_lifecycle_hook_event self = <azure.cli.testsdk.base.ExecutionResult object at 0x7f6ae0fdde50>
cli_ctx = <azure.cli.core.mock.DummyCli object at 0x7f6ae2bd8410>
command = 'vmss lifecycle-hook-event list -g cli_test_vmss_lch_event000001 --vmss-name vmss000002'
expect_failure = False

    def in_process_execute(self, cli_ctx, command, expect_failure=False):
        from io import StringIO
        from vcr.errors import CannotOverwriteExistingCassetteException
    
        if command.startswith('az '):
            command = command[3:]
    
        stdout_buf = StringIO()
        logging_buf = StringIO()
        try:
            # issue: stderr cannot be redirect in this form, as a result some failure information
            # is lost when command fails.
>           self.exit_code = cli_ctx.invoke(shlex.split(command), out_file=stdout_buf) or 0
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/azure-cli-testsdk/azure/cli/testsdk/base.py:303: 
                                        
env/lib/python3.14/site-packages/knack/cli.py:245: in invoke
    exit_code = self.exception_handler(ex)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/init.py:153: in exception_handler
    return handle_exception(ex)
           ^^^^^^^^^^^^^^^^^^^^
                                        

ex = ModuleNotFoundError("No module named 'azure.cli.command_modules.vm.aaz.latest.vmss.lifecycle_hook_event.list'")
args = (), kwargs = {}

    def handle_main_exception(ex, *args, **kwargs):  # pylint: disable=unused-argument
        if isinstance(ex, CannotOverwriteExistingCassetteException):
            # This exception usually caused by a no match HTTP request. This is a product error
            # that is caused by change of SDK invocation.
            raise ex
    
>       raise CliExecutionError(ex)
E       azure.cli.testsdk.exceptions.CliExecutionError: The CLI throws exception ModuleNotFoundError during execution and fails the command.

src/azure-cli-testsdk/azure/cli/testsdk/patches.py:35: CliExecutionError

During handling of the above exception, another exception occurred:

self = <latest.test_vm_commands.VMSSLifecycleHookEventScenarioTest testMethod=test_vmss_lifecycle_hook_event>
resource_group = 'cli_test_vmss_lch_event000001'

    @AllowLargeResponse()
    @ResourceGroupPreparer(name_prefix='cli_test_vmss_lch_event')
    # Not including approve/reject/show and update --action-state as they required live platform-generated event
    def test_vmss_lifecycle_hook_event(self, resource_group):
        self.kwargs.update({
            'vmss': self.create_random_name('vmss', 15)
        })
        self.cmd('vmss create -g {rg} -n {vmss} --image Ubuntu2204 --admin-username myadmin '
                 '--admin-password testPassword0 --orchestration-mode Uniform --instance-count 2 '
                 '--vm-sku Standard_D2s_v3')
    
        # Lifecycle hook events are platform-generated; a fresh scale set has none.
>       self.cmd('vmss lifecycle-hook-event list -g {rg} --vmss-name {vmss}',
                 checks=[self.check('length(@)', 0)])

src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:4739: 
 
 
                                      
src/azure-cli-testsdk/azure/cli/testsdk/base.py:177: in cmd
    return execute(self.cli_ctx, command, expect_failure=expect_failure).assert_with_checks(checks)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-testsdk/azure/cli/testsdk/base.py:252: in init
    self.in_process_execute(cli_ctx, command, expect_failure=expect_failure)
src/azure-cli-testsdk/azure/cli/testsdk/base.py:315: in in_process_execute
    raise ex.exception
env/lib/python3.14/site-packages/knack/cli.py:233: in invoke
    cmd_result = self.invocation.execute(args)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:677: in execute
    raise ex
src/azure-cli-core/azure/cli/core/commands/init.py:820: in run_jobs_serially
    results.append(self.run_job(expanded_arg, cmd_copy))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:789: in run_job
    result = cmd_copy(params)
             ^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/init.py:335: in call
    return self.handler(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src/azure-cli-core/azure/cli/core/commands/command_operation.py:120: in handler
    return op(**command_args)
           ^^^^^^^^^^^^^^^^^^
 
 
 
 
 
                                   

cmd = <azure.cli.core.commands.AzCliCommand object at 0x7f6ae0e58750>
resource_group_name = 'cli_test_vmss_lch_event000001', vmss_name = 'vmss000002'

    def vmss_lifecycle_hook_event_list(cmd, resource_group_name, vmss_name):
        from azure.cli.core.commands.transform import unregister_global_transforms
>       from .aaz.latest.vmss.lifecycle_hook_event._list import List as _lifecycleHookEventList
E       ModuleNotFoundError: No module named 'azure.cli.command_modules.vm.aaz.latest.vmss.lifecycle_hook_event._list'

src/azure-cli/azure/cli/command_modules/vm/custom.py:5201: ModuleNotFoundError
azure/cli/command_modules/vm/tests/latest/test_vm_commands.py:4726

Copilot AI review requested due to automatic review settings July 21, 2026 05:53
@william051200
william051200 requested a review from a team as a code owner July 21, 2026 05:53
@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi @william051200,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@william051200 william051200 changed the title {Compute} az vmss lifecycle-hooks &az vmss lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks {Compute} az vmss lifecycle-hooks/ lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks Jul 21, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Auto-Assign Auto assign by bot label Jul 21, 2026
@william051200 william051200 changed the title {Compute} az vmss lifecycle-hooks/ lifecycle-hooks-event: Add new command groups to support vmss lifecycle hooks {Compute} az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds new preview command groups under the vmss command module to manage VM Scale Set lifecycle hooks and to interact with platform-generated lifecycle hook events, along with scenario tests and recordings.

Changes:

  • Add az vmss lifecycle-hook commands (add/update/remove/show/list) backed by new custom implementations.
  • Add az vmss lifecycle-hook-event commands, including AAZ-generated list/show/update and custom wrappers for update/approve/reject with client-side validation.
  • Add scenario tests and a recording to validate core command behaviors.

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/azure-cli/azure/cli/command_modules/vm/tests/latest/test_vm_commands.py Adds scenario tests for lifecycle-hook and lifecycle-hook-event command groups.
src/azure-cli/azure/cli/command_modules/vm/tests/latest/recordings/test_vmss_lifecycle_hook_event.yaml Adds recording for lifecycle-hook-event list scenario.
src/azure-cli/azure/cli/command_modules/vm/custom.py Implements lifecycle hook CRUD and lifecycle hook event update/approve/reject helpers.
src/azure-cli/azure/cli/command_modules/vm/commands.py Registers new command groups and wires validators.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_update.py Adds AAZ-generated vmss lifecycle-hook-event update.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_show.py Adds AAZ-generated vmss lifecycle-hook-event show.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/_list.py Adds AAZ-generated vmss lifecycle-hook-event list.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/init.py Exposes lifecycle_hook_event AAZ commands for loading.
src/azure-cli/azure/cli/command_modules/vm/aaz/latest/vmss/lifecycle_hook_event/__cmd_group.py Registers the AAZ command group for lifecycle hook events.
src/azure-cli/azure/cli/command_modules/vm/_validators.py Adds validators for hook removal and lifecycle-hook-event update/action behaviors.
src/azure-cli/azure/cli/command_modules/vm/_params.py Adds argument definitions/enums for lifecycle hook and lifecycle hook event commands.
src/azure-cli/azure/cli/command_modules/vm/_help.py Adds help content for the new command groups/commands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# AZURE CLI VM TEST DEFINITIONS
import json
import os
import datetime
Comment on lines +5123 to +5131
def _commit_vmss_lifecycle_hooks(cmd, resource_group_name, vmss_name, hooks, no_wait):
from .operations.vmss import VMSSCreate, convert_show_result_to_snake_case
vmss = get_vmss_modified_by_aaz(cmd, resource_group_name, vmss_name)
vmss = convert_show_result_to_snake_case(vmss)
vmss["lifecycle_hooks_profile"] = {"lifecycle_hooks": hooks}
vmss["resource_group"] = resource_group_name
vmss["vm_scale_set_name"] = vmss_name
vmss["no_wait"] = no_wait
return VMSSCreate(cli_ctx=cmd.cli_ctx)(command_args=vmss)
Comment on lines +3079 to +3082
helps['vmss lifecycle-hook-event'] = """
type: group
short-summary: Manage virtual machine scale set lifecycle hook events.
"""
@william051200 william051200 changed the title {Compute} az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks [Compute] az vmss lifecycle-hook/ lifecycle-hook-event: Add new command groups to support vmss lifecycle hooks Jul 21, 2026
@yonzhan

yonzhan commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Compute

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@AnshulVermaa

Copy link
Copy Markdown
Member
  1. lifecycle-hook-event commands apart from show and list fail with exit code -1 (even though the underlying operation on CRP side succeeds).
  2. lifecycle-hook-event show and list have a resource group field appended at the end of the response.
  3. az vmss lifecycle-hook add: 'TestLCH' is not a valid value for '--type'. Allowed values: UpgradeAutoOSScheduling, UpgradeAutoOSRollingBatchStarting. Is this validation on PS side, and every time we surface new LCH type, would we need PS changes and rollout as well?

@AnshulVermaa AnshulVermaa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments added in discussions

@a0x1ab

a0x1ab commented Jul 27, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@a0x1ab

a0x1ab commented Jul 27, 2026

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@william051200

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad Auto-Assign Auto assign by bot Compute az vm/vmss/image/disk/snapshot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add VMSS Lifecycle Hooks support to az vmss (preview)

6 participants